#pragma once

#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

#include <string>

#include "util/status.h"

namespace hawking {
namespace indexlib {

class NormalFileWriter {
public:
    NormalFileWriter(const std::string& filename) : filename_(filename) {}
    ~NormalFileWriter() {
        Close();
        fd_ = -1;
        file_size_ = -1;
        filename_ = "";
    }

    Status Init();
    void ReserveFile(size_t length);
    ReturnValue<size_t> Write(uint8_t* buf, size_t len, off_t offset = 0);
    void Close() {
        close(fd_);
    }

private:
    int32_t fd_ = -1;
    int32_t file_size_ = -1;
    std::string filename_ = "";
};

}
}